extends CenterContainer


var edit_data = null

onready var source_sprite_op = $PanelContainer/VBoxContainer/source/SpriteSelectPlus
onready var target_sprite_op = $PanelContainer/VBoxContainer/target/SpriteSelectPlus
onready var target_level = $PanelContainer/VBoxContainer/level/SpinBox
onready var desc = $PanelContainer/VBoxContainer/desc/LineEdit
signal close


func set_edit_data(data):
	self.edit_data = data
	
	if edit_data:
		source_sprite_op.set_value(data["sourcePokemonId"])
		target_sprite_op.set_value(data["targetPokemonId"])
		target_level.value = int(data.get("targetPokemonLevel",1))
		desc.text = data.get("description","")


func _on_cancel_button_up():
	MainTool.getUILayer().pop_ui()


func _on_ok_button_up():
	if edit_data:
		edit_data["sourcePokemonId"] = source_sprite_op.get_value()
		edit_data["targetPokemonId"] = target_sprite_op.get_value()
		edit_data["targetPokemonLevel"] = target_level.value
		edit_data["description"] = desc.text
			
		DataSource.update_data(DataSource.sprite_change, edit_data)
		
		MainTool.toast_info("更新成功!")
	else:
		var data = {
			"sourcePokemonId": source_sprite_op.get_value(),
			"targetPokemonId": target_sprite_op.get_value(),
			"targetPokemonLevel": target_level.value,
			"description": desc.text,
		}
		
		DataSource.add_data(DataSource.sprite_change, data)
	
		MainTool.toast_info("添加成功!")
	
	MainTool.getUILayer().pop_ui()
	
	emit_signal("close")
